package gui.author;

import gui.CAControl;

import java.awt.Color;
import java.awt.GridLayout;
import java.util.Observable;
import java.util.Observer;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.Border;

import caobject.Conference;
import caobject.Manuscript;

/**
 * Conference Assistant Center Panel
 * 
 * @author Bob Rankin
 * @author Brian M. Luger
 * @version 11/27/2011
 */
@SuppressWarnings("serial")
public class AuthorCenterPanel extends JPanel implements Observer 
{
	
	/*
	 * Conference Reference
	 */
	private final Conference my_conf;
	
	/*
	 * Control Reference
	 */
	private final CAControl my_control;
	
	/*
	 * Panel Text Area
	 */
	private final JTextArea my_manuscriptText
	 	= new JTextArea(24, 65);	

	/*
	 * List of Manuscripts
	 */
	private final JTextArea my_manuscript_list
		= new JTextArea(20, 50);	
	
	/**
	 * Conference Assistant Center Panel Constructor.
	 * 
	 * @param the_conf Conference Reference
	 * @param the_control Control Reference
	 */
	public AuthorCenterPanel(final Conference the_conf,
			final CAControl the_control) 
	{
		my_conf = the_conf;
		my_control = the_control;
		my_control.addObserver(AuthorCenterPanel.this);
		
		setup();
	}
	
	/**
	 * Panel Setup Method
	 */
	private void setup() 
	{
		// TODO: Code to display manuscripts
		
		// FILLER FOR NOW
		setLayout(new GridLayout(1,10));
		
		Border matteBorder = BorderFactory.
		createMatteBorder(5, 5, 5, 5, Color.BLACK);
		final Border titleBorder = BorderFactory.
		createTitledBorder(matteBorder, "Manuscripts");
		setBorder(titleBorder);
		
		add(new JScrollPane(my_manuscriptText));
	}

	/**
	 * Method used to update the panel
	 */
	@Override
	public void update(final Observable the_observable, 
			final Object the_obj) 
	{
		// TODO Appropriate update method...
		final StringBuilder sb = new StringBuilder();
		my_manuscript_list.setText("");
		for (Manuscript aManuscript : my_conf.getManuscripts()) {
			if (aManuscript.getAuthor().
					equalsIgnoreCase(my_control.getSelectedUser())) {
				sb.append(aManuscript.getTitle() + "\n");
			}
		}
		my_manuscriptText.setText(sb.toString());
	}
}
